package pe.edu.sistemas.postgrado.samupg.domain.model;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "examen", catalog = "bd_samupg")
public class Examen implements java.io.Serializable {

    private Integer examenId;
    private Periodo periodo;
    private List<Pregunta> preguntas = new ArrayList<Pregunta>(0);

    public Examen() {
    }

    public Examen(Periodo periodo) {
        this.periodo = periodo;
    }

    public Examen(Periodo periodo, List<Pregunta> preguntas) {
        this.periodo = periodo;
        this.preguntas = preguntas;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "examen_id", unique = true, nullable = false)
    public Integer getExamenId() {
        return this.examenId;
    }

    public void setExamenId(Integer examenId) {
        this.examenId = examenId;
    }

    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "examen_periodo_id", nullable = false)
    public Periodo getPeriodo() {
        return this.periodo;
    }

    public void setPeriodo(Periodo periodo) {
        this.periodo = periodo;
    }

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "examen_pregunta", catalog = "bd_samupg", joinColumns = {
        @JoinColumn(name = "ep_exam_id", nullable = false, updatable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "ep_preg_id", nullable = false, updatable = false)})
    @Fetch(value = FetchMode.SUBSELECT)
    public List<Pregunta> getPreguntas() {
        return this.preguntas;
    }

    public void setPreguntas(List<Pregunta> preguntas) {
        this.preguntas = preguntas;
    }
}
